package com.eclab.redis.controller;

import com.alibaba.fastjson.JSONArray;
import com.eclab.redis.model.Province;
import com.eclab.redis.service.ProvinceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: ToDo
 * @author: marin
 * @time: 2020/5/13 16:21
 */

@Slf4j
@Controller
@RequestMapping("/redis")
@Api(value = "省份信息",tags = {"Redis存取"})
public class ProvinceController {

    @Resource
    private ProvinceService provinceService;

    @ApiOperation(value = "从redis中获取省份列表")
    @RequestMapping(value = "/getAllProvinces",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public JSONArray getAllProvinces(){
        provinceService.findAllProvinces();
        JSONArray lists = provinceService.getProvicesFromRedis();
        return lists;
    }

    @ApiOperation(value = "从mysql中获取省份列表")
    @RequestMapping(value = "/getProvinces",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public List<Province> getProvincesFromMysql(){
        List<Province> provinces = provinceService.findAllProvinces();
        return provinces;
    }
}
